﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication2
{
    public partial class WebForm3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["name"]==null||Request.Cookies["password"]==null) {
                Response.Redirect("WebForm2.aspx");
            }
            if (Application["chatroom"]==null) {
                Application["chatroom"] = new Panel();
            }
            Panel1.Controls.Add((Panel)Application["chatroom"]);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string text = TextBox1.Text;
            string name = (string)Session["name"];
            string time = DateTime.Now.ToString();

            Literal literal = new Literal();
            literal.Text = $"{name},{time}:{text}<br />";
            Panel panel =(Panel)Application["chatroom"];
            panel.Controls.Add(literal);
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            Session.Abandon();
            Response.Redirect("WebForm2.aspx");
        }
    }
}